package com.project.service;

import com.project.dao.CvMapper;
import com.project.dao.JobApplyMapper;
import com.project.entity.JobApply;
import com.project.service.base.BaseService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

//让checked例外也回滚
@Transactional(rollbackFor = Exception.class)
@Service
public class JobApplyServiceImpl extends BaseService implements JobApplyService {
    private static JobApplyMapper jobApplyMapper = null;

    public void setMapper() {
        if (jobApplyMapper == null)
            jobApplyMapper = sqlSessionTemplate.getMapper(JobApplyMapper.class);//1.获取相关mapper
    }

    /**
     * author: WheelChen
     * date: 2017/9/4
     * function: 添加一条应聘记录
     *
     * @param jobApply
     * @return
     */
    @Override
    public int addOne(JobApply jobApply) {
        setMapper();
        return jobApplyMapper.insertSelective(jobApply);
    }

    /**
     * author: WheelChen
     * date: 2017/9/4
     * function: 根据id删除一条应聘记录
     *
     * @param id
     * @return
     */
    @Override
    public int removeOneById(Integer id) {
        setMapper();
        return jobApplyMapper.deleteByPrimaryKey(id);
    }

    /**
     * author: WheelChen
     * date: 2017/9/4
     * function: 根据id修改一条应聘记录
     *
     * @param jobApply
     * @return
     */
    @Override
    public int modifyOneById(JobApply jobApply) {
        setMapper();
        return jobApplyMapper.updateByPrimaryKeySelective(jobApply);
    }

    /**
     * author: WheelChen
     * date: 2017/9/5
     * function: 根据id查找应聘表
     *
     * @param id
     * @return
     */
    @Override
    public JobApply findOneById(Integer id) {
        setMapper();
        return jobApplyMapper.selectByPrimaryKey(id);
    }

    /**
     * author: WheelChen
     * date: 2017/9/9
     * function: 根据应聘表模糊条件查找
     *
     * @param jobApply
     * @return
     */
    @Override
    public List<JobApply> findByCondition(JobApply jobApply) {
        setMapper();
        return jobApplyMapper.selectByCondition(jobApply);
    }

    /**
     * author: WheelChen
     * date: 2017/9/19
     * function: 根据学生信息表idList批量删除
     *
     * @param studentInfoIdList
     * @return
     */
    @Override
    public int removeBatchByStudentInfoIdList(List studentInfoIdList) {
        setMapper();
        return jobApplyMapper.deleteBatchByStudentInfoIdList(studentInfoIdList);
    }
}
